import proj4 from 'proj4'

proj4.defs([
  ['EPSG:4326', '+proj=longlat +datum=WGS84 +no_defs'],
  [
    'EPSG:4545',
    '+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs'
  ],
  [
    'EPSG:4547',
    '+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs'
  ],
  [
    'EPSG:3857',
    '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs'
  ]
])
/**
 * xy是数组['经度','纬度']
 */
const _turf = {
  transform(xy) {
    let result = proj4('EPSG:4326', 'EPSG:4547', xy)
    return result
  },

  reTransform(xy) {
    let result = proj4('EPSG:4547', 'EPSG:4326', xy)
    return result
  }
}

export default _turf
